package nc.api.boda.mes.utils;

import com.alibaba.fastjson.JSONObject;

import nc.api.boda.mes.base.entity.ResponseEntity;
import nc.api.boda.mes.common.MesApiConstant;

public class BodaResponseUtil {

	public static ResponseEntity creartOKBean(Object data, String message) {
		ResponseEntity entity = new ResponseEntity();
		entity.setSuccess(true);
		entity.setData(data);
		entity.setMessage(message == null ? "Success" : message);
		entity.setErrorCode("0000");
		return entity;
	}

	public static ResponseEntity creartErrorBean(Object data, String message, String errCode) {
		ResponseEntity entity = new ResponseEntity();
		entity.setSuccess(false);
		entity.setData(data);
		entity.setMessage(message);
		entity.setErrorCode(errCode);
		return entity;
	}
	
	public static JSONObject transf(ResponseEntity entity) {
		JSONObject result = new JSONObject();
		result.put("detail", entity.getData());
		result.put("result", entity.isSuccess() ? MesApiConstant.SUCCESS : MesApiConstant.FAILED);
		String code = entity.getErrorCode();
		result.put("code", code == null ? "9999" : code);
		result.put("msg", entity.getMessage());
		return result;
	}
}
